#ifndef thread_api_h
#define thread_api_h
#include "t_config.h"

struct t_thread_runner;
typedef void (*thread_func_call)(void* param);
struct t_thread_runner* t_thread_runner_create(thread_func_call,void*);
void t_thread_runner_destroy(struct t_thread_runner);
/*ret : 1 suc 0:failure*/
int t_thread_runner_start(struct t_thread_runner*);
void t_thread_runner_stop(struct t_thread_runner*);
thread_id_t t_thread_get_id(struct t_thread_runner*);
void t_thread_runner_join(struct t_thread_runner*);
thread_id_t t_thread_get_self();
void t_thread_sleep_ms(int);

t_atomic atomic_inc(t_atomic*);
t_atomic atomic_dec(t_atomic*);
t_atomic atomic_cas(t_atomic*,t_atomic,t_atomic);
t_atomic atomic_set(t_atomic*,t_atomic);
int atomic_zero(t_atomic*);

struct t_lock;
struct t_lock* t_lock_create();
void t_lock_destry(struct t_lock*);
void t_lock_lock(struct t_lock*);
void t_lock_trylock(struct t_lock*);
void t_lock_unlock(struct t_lock*);

struct t_rwlock;
struct t_rwlock* t_rwlock_create();
void t_rwlock_destroy(struct t_rwlock*);
void t_rwlock_rdlock(struct t_rwlock*);
void t_rwlock_rdunlock(struct t_rwlock*);
void t_rwlock_wrlock(struct t_rwlock*);
void t_rwlock_wrunlock(struct t_rwlock*);

struct t_cond;
struct t_cond* t_cond_create();
void t_cond_destroy(struct t_cond*);
void t_cond_wait(struct t_cond*,struct t_lock);
void t_cond_signal(struct t_cond*);
#endif